/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.dusa.switco;

/**
 * Singleton class containing global settings for the schedule calculation.
 * @author vdusa
 */
public class GlobalSettings {
    private Double minT = new Double(-100);
    private Double maxT = new Double(100);
    private Double precisionLimit = new Double(0.001);
    private static GlobalSettings instance = null;

    private GlobalSettings(){
    }

    /**
     * @return Singleton instance of the GlobalSettings class
     */
    public static GlobalSettings getInstance(){
        if (instance==null){
            instance = new GlobalSettings();
        }
        return instance;
    }

    /**
     * minT is the lowest time point in the schedule
     * @return the minT
     */
    public Double getMinT() {
        return minT;
    }

    /**
     * see {@link cz.dusa.switco.GlobalSettings#getMinT()}.
     * @param minT the minT to set
     */
    public void setMinT(Double minT) {
        this.minT = minT;
    }

    /**
     * maxT is the latest time point in the schedule
     * @return the maxT
     */
    public Double getMaxT() {
        return maxT;
    }

    /**
     * see {@link cz.dusa.switco.GlobalSettings#getMaxT()}.
     * @param maxT the maxT to set
     */
    public void setMaxT(Double maxT) {
        this.maxT = maxT;
    }

    /**     
     * @return the precision limit of the numerical methods (e.g. {@link ConvexCostFunctionSum#getArgMin()})
     */
    public Double getPrecisionLimit() {
        return precisionLimit;
    }

    /**
     * @param precisionLimit the precisionLimit to set
     */
    public void setPrecisionLimit(Double precisionLimit) {
        this.precisionLimit = precisionLimit;
    }

    /**
     * Rounds the given number to the precision limit. See {@link #setPrecisionLimit(java.lang.Double)}
     * @param number to be rounded
     * @return rounded number
     */
    public Double roundToPrecisionLimit(double number){
        Double value = number / getPrecisionLimit();
        long tmp = Math.round(value);
        return (double)tmp*getPrecisionLimit();
    }
}
